package com.util;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class MyCheckBox {
    private List<JCheckBox> checkBoxlist = new ArrayList();

    public MyCheckBox(String titleInfo, String[] items, int x, int y, Container con) {
        JLabel jl = new JLabel(titleInfo);
        jl.setBounds(x, y, 80, 20);
        con.add(jl);

        if (items != null && items.length != 0) {
            int dix = 0;

            for(int i = 0; i < items.length; ++i) {
                JCheckBox jrb = new JCheckBox(items[i]);
                jrb.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
//                            String str = jrb.getText();
                            addListener();
                    }
                });
                jrb.setBounds(x + 100 + (i - dix * 3) * 140, y + dix * 40, 120, 20);
                if ((i + 1) % 3 == 0) {
                    ++dix;
                }
                con.add(jrb);
                this.checkBoxlist.add(jrb);
            }
        }
    }

    /** @deprecated */
    @Deprecated
    public String[] getItem() {
        List<String> list = new ArrayList();
        Iterator var3 = this.checkBoxlist.iterator();

        while(var3.hasNext()) {
            JCheckBox jcb = (JCheckBox)var3.next();
            if (jcb.isSelected()) {
                list.add(jcb.getText());
            }
        }

        String[] strs = new String[list.size()];

        for(int i = 0; i < list.size(); ++i) {
            strs[i] = (String)list.get(i);
        }

        return strs;
    }

    public String[] getSelectItem() {
        List<String> list = new ArrayList();
        Iterator var3 = this.checkBoxlist.iterator();

        while(var3.hasNext()) {
            JCheckBox jcb = (JCheckBox)var3.next();
            if (jcb.isSelected()) {
                list.add("是");
            } else {
                list.add("否");
            }
        }

        String[] strs = (String[])list.toArray(new String[0]);
        return strs;
    }

    /** @deprecated */
    @Deprecated
    public void setItem(String[] items) {
        Iterator var3 = this.checkBoxlist.iterator();

        while(var3.hasNext()) {
            JCheckBox jcb = (JCheckBox)var3.next();
            jcb.setSelected(false);
        }

        String[] var5 = items;
        int var4 = items.length;

        for(int var9 = 0; var9 < var4; ++var9) {
            String item = var5[var9];
            Iterator var7 = this.checkBoxlist.iterator();

            while(var7.hasNext()) {
                JCheckBox jcb = (JCheckBox)var7.next();
                if (jcb.getText().equals(item)) {
                    jcb.setSelected(true);
                    break;
                }
            }
        }

    }

    public void setSelectItem(String[] items) {
        Iterator var3 = this.checkBoxlist.iterator();

        while(var3.hasNext()) {
            JCheckBox jcb = (JCheckBox)var3.next();
            jcb.setSelected(false);
        }

        for(int i = 0; i < items.length; ++i) {
            if (items[i].equals("是")) {
                ((JCheckBox)this.checkBoxlist.get(i)).setSelected(true);
            }
        }
    }

    public void addListener(){

    }

    public List<JCheckBox> getCheckBoxlist() {
        return checkBoxlist;
    }

    public void setCheckBoxlist(List<JCheckBox> checkBoxlist) {
        this.checkBoxlist = checkBoxlist;
    }
}
